<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility" %>
<%@ include file="/public/header.jsp"%>

<html>
	<head>
		<title>项目开票收款管理</title>
	</head>
	<script type="text/javascript">
		$(function(){
			$("#table").datagrid({
				title:"项目开票收款管理",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/xmFinance/listPageXMInvoice',
				rownumbers:true,
				fitColumns:true,
				nowrap:false,
				idField:'id',
				frozenColumns:[[
				    {title:'主键',field:'id',hidden:true},
				]],
				columns:[[
					{title:'项目编号',field:'xm_code',width:100,align:'center'},
					{title:'项目名称',field:'xm_name',width:200,align:'center'},
					{title:'票据抬头',field:'invoice_title',width:100,align:'center'},
					{title:'开票人',field:'creator',width:100,align:'center'},
					{title:'开票额',field:'account_receivable',width:100,align:'center'},
					{title:'已收额',field:'has_receivable',width:100,align:'center'},
					{title:'预警时间',field:'alarm_time',width:100,align:'center'},
					{title:'备注',field:'remark',width:100,align:'center'},
					{title:'创建时间',field:'create_time',width:100,align:'center'},
					{title:'审核状态',field:'status',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						if(value==1){
							return "审核中";
						}else if(value==2){
							return "审核不通过";
						}else if(value==3){
							return "审核通过";
						}
						return "未提交审核";
					}},
					{title:'收款操作',field:'more',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						var str="";
						if(rowData.status == 3){
							if(rowData.has_receivable<rowData.account_receivable){ 
							str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-add' title='新增收款' onclick=\"javascript:addInMoney('"+rowData.xm_id+"','"+rowData.xm_code+"','"+rowData.xm_name+"','"+rowData.invoice_title+"','"+rowData.id+"','"+rowData.account_receivable+"','"+rowData.has_receivable+"');\"/>&nbsp;&nbsp;";
							}
							str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='详情' onclick=\"javascript:viewInMoneyData('"+rowData.id+"');\"/>";
						}
						else
						{
	                    	str+="无";
						}
	                    return str;
					}},
					{title:'详情操作',field:'more',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						var str="";
						if(rowData.status == 0  || rowData.status == 2){
							str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:editXMInvoice('"+rowData.id+"');\"/> &nbsp;&nbsp;";
							str+="<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批' onclick=\"javascript:shenpi(this,'"+rowData.id+"');\"/> &nbsp;&nbsp;";
							str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-no' title='删除' onclick=\"javascript:deleteData('"+rowData.id+"');\"/>&nbsp;&nbsp;";
						}
						if(rowData.status>0){
							str+="<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审核查看' onclick=\"javascript:viewFlowView('"+encodeURIComponent("<%=FlowUtility.XM_INVOICE_SHENPI%>")+"','"+rowData.id+"');\"/>&nbsp;&nbsp;";
						}
						if(rowData.status>0){
	                    	str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='详情' onclick=\"javascript:viewData('"+rowData.id+"');\"/>";
						}
	                    return str;
					}}
				]],
				
				toolbar:
				[
				   {
						id:'add',
						text:'新增',
						iconCls:"icon-add",
						handler:function(){
							addInvoice();
						}
					}
				],
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});
		function addInMoney(xm_id,xm_code,xm_name,invoice_title,invoiceId,account_receivable,has_receivable){
        	var para="xm_id="+xm_id+"&xm_code="+encodeURIComponent(xm_code)+"&xm_name="+encodeURIComponent(xm_name)+"&invoice_title="+encodeURIComponent(invoice_title)+"&invoiceId="+invoiceId+"&account_receivable="+account_receivable+"&has_receivable="+has_receivable;
        	openDialogResize("<%=contextPath %>/springViews/xm/addOrEditInMoney.jsp?"+para+"&callback=rtCallBack&isShow=0",1000, 800);
        }
        function addInvoice(){
        	 //var para="xm_id="+id+"&xm_code="+encodeURIComponent(xm_code)+"&xm_name="+encodeURIComponent(xm_name)+"&dept_id="+dept_id+"&dept_name="+encodeURIComponent(dept_name)+"&customer_id="+customer_id+"&customer="+encodeURIComponent(customer);
        	openDialogResize("<%=contextPath %>/springViews/xm/addOrEditInvoice.jsp?callback=rtCallBack",1000, 800);
        }
		function shenpi(obj,id){
	    	//flowBusinessUrl获取审批业务记录的URL(可以是个组合参数字符串),moduleFlow获取工作流程的流程名称
	      var flowBusinessUrl="<%=contextPath %>/springViews/xm/viewXmInvoice.jsp?id="+id;
	      var param="flowBusinessUrl="+encodeURIComponent(flowBusinessUrl)+"&moduleFlow="+encodeURIComponent("<%=FlowUtility.XM_INVOICE_SHENPI%>")+"&businessId="+id+"&isShow=1";
	      $(obj).hide();
	      $.ajax({
						type:'POST',
						url:'<%=contextPath %>/springMVC/workFlow/toShenpi',
						dataType:"JSON",
						data:param,
						success:function(rtJson){
							if (rtJson.rtState == '0'){
								openDialogResize(rtJson.rtData.url,1000,800);
							}else{
								warningInfo(rtJson.rtMsrg);
							}
							$(obj).show();
						}
					});
	       
	    } 
		
		function deleteData(id){
			var rows=$('#table').datagrid('getSelections');
			$.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/xmFinance/deleteInvoice",
						data:"id="+id,
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}

		function  editXMInvoice(id){
				alert("开发中");
				return ;
			//openDialogResize("<%=contextPath %>/springViews/xm/addOrEditXm.jsp?id="+id+"&callback=rtCallBack&isShow=0",1000, 800);
	
		}
		function  viewData(id){
			openDialogResize("<%=contextPath %>/springViews/xm/viewXmInvoice.jsp?id="+id+"&callback=rtCallBack&isShow=1",1000, 800);
		}
		function  viewInMoneyData(id){
			openDialogResize("<%=contextPath %>/springViews/xm/xmInMoney.jsp?invoice_id="+id+"&callback=rtCallBack&isShow=1",1000, 800);
		}

		function rtCallBack(){
			$('#table').datagrid('reload');
		}

	</script>
	<body style="height: 97%">
		<div id="table" data-options="fit:true" ></div>
	</body>
</html>
